<?php 


abstract class ActiveRecord {
	
	
	protected $tablename;
	public $dbobj;
	
	
	public function insert() {
		
		global $DB;
		
		return $DB->insertObject($this->tablename, $this->dbobj);
	}
	
	
	public function update() {
		
		global $DB;
		
		if (empty($this->dbobj->id) || !$this->dbobj->id) {
			return false;
		}
		
		$sets = clone $this->dbobj;
		unset($sets->id);
		
		return $DB->updateObject($this->tablename, $sets, $this->dbobj->id);
	}
	
	
	public function get() {

		global $DB;
		
		if (empty($this->dbobj->id)) {
			return false;
		}
		
		$sql = "SELECT * FROM ".$this->tablename." WHERE id = ?";
		$this->dbobj = $DB->selectResponse($sql, array($this->dbobj->id));
		
		return $this->dbobj;
	}
	
}


?>